/*
 * \brief  C-library back end
 * \author Norman Feske
 * \date   2008-11-11
 */

/*
 * Copyright (C) 2008-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>

extern "C" int raw_write_str(const char *s);

extern "C" int _fstat(int fd, struct stat *buf)
{
	/* printf inqueries _fstat about stdout */
	if (fd == 1) {

		/*
		 * The following values were obtained with small test program that
		 * calls fstat for stdout on linux.
		 */
		buf->st_dev     =    11;
		buf->st_ino     =     4;
		buf->st_mode    =  8592;
		buf->st_nlink   =     1;
		buf->st_uid     =     0;
		buf->st_gid     =     0;
		buf->st_rdev    = 34818;
		buf->st_size    =     0;
		buf->st_blksize =  1024;
		buf->st_blocks  =     0;

		return 0;

	} else {
		int i;

		raw_write_str("fstat called for fd <");

		for (i = 0; i < fd; i++)
			raw_write_str("*");
		raw_write_str(">\n");

		errno = EBADF;
		return -1;
	}
}

